### Elixir statements for the validations

from sqlalchemy_validations import *
from elixir.statements import Statement

class ElixirValidatesPresenceOf(object):
    def __init__(self, entity, *args):
        for fieldname in args:
            entity._descriptor.add_mapper_extension(Validator(presence_of(fieldname)))

class ElixirValidatesRangeOf(object):
    def __init__(self, entity, fieldname, min, max):
        entity._descriptor.add_mapper_extension(Validator(range_of(fieldname, min, max)))

class ElixirValidatesFormatOf(object):
    def __init__(self, entity, fieldname, regex):
        entity._descriptor.add_mapper_extension(Validator(format_of(fieldname, regex)))


validates_presence_of = Statement(ElixirValidatesPresenceOf)
validates_range_of    = Statement(ElixirValidatesRangeOf)
validates_format_of   = Statement(ElixirValidatesFormatOf)

__all__ = ['validates_presence_of', 'validates_format_of', 'validates_range_of', 'ValidationException']
